// import com.alibaba.druid.sql.ast.SQLExpr_ptr;
// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.SQLObjectImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "SQLAlterTableRename.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/instanceof.h"
#include "SQLExprTableSource.h"

SQLAlterTableRename::SQLAlterTableRename()
{
}

SQLAlterTableRename::SQLAlterTableRename(SQLExpr_ptr to)
{
  this->setTo(to);
}

SQLExprTableSource_ptr SQLAlterTableRename::getTo()
{
  return to;
}

SQLName_ptr SQLAlterTableRename::getToName()
{
  if (to == nullptr)
  {
    return nullptr;
  }

  SQLExpr_ptr expr = to->expr;

  if (instanceof <SQLExpr, SQLName>(expr))
  {
    return std::dynamic_pointer_cast<SQLName>(expr);
  }

  return nullptr;
}

void SQLAlterTableRename::setTo(SQLExprTableSource_ptr to)
{
  if (to != nullptr)
  {
    to->setParent(SharedObject(SQLAlterTableRename));
  }
  this->to = to;
}

void SQLAlterTableRename::setTo(SQLExpr_ptr to)
{
  this->setTo(SQLExprTableSource_ptr(new SQLExprTableSource(to)));
}

// @Override
void SQLAlterTableRename::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLAlterTableRename)))
  {
    acceptChild(visitor, to);
  }
  visitor->endVisit(SharedObject(SQLAlterTableRename));
}
